﻿using MediatR;
using Order.Api.Read.Application.Command;
using Order.Api.Read.Dto.Order;
using Order.Api.Read.Service.InterrogationOrderService;
using Order.ErrorCode;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Order.Api.Read.Application.Handler
{
    /// <summary>
    /// 问诊订单分页查询处理器
    /// </summary>
    public class InterrogationOrderPageHandler : IRequestHandler<InterrogationOrderPageCommand, ApiPageIng<InterrogationOrderPageDto>>
    {
        private readonly IInterrogationOrderService _interrogationOrderService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="interrogationOrderService">问诊订单服务</param>
        public InterrogationOrderPageHandler(IInterrogationOrderService interrogationOrderService)
        {
            _interrogationOrderService = interrogationOrderService ?? throw new ArgumentNullException(nameof(interrogationOrderService));
        }

        /// <summary>
        /// 处理问诊订单分页查询请求
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>分页结果</returns>
        public async Task<ApiPageIng<InterrogationOrderPageDto>> Handle(InterrogationOrderPageCommand request, CancellationToken cancellationToken)
        {
            return await _interrogationOrderService.GetInterrogationOrderPageAsync(request);
        }
    }

    /// <summary>
    /// 问诊订单详情查询处理器
    /// </summary>
    public class InterrogationOrderDetailHandler : IRequestHandler<InterrogationOrderDetailCommand, ApiResult<InterrogationOrderDetailDto>>
    {
        private readonly IInterrogationOrderService _interrogationOrderService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="interrogationOrderService">问诊订单服务</param>
        public InterrogationOrderDetailHandler(IInterrogationOrderService interrogationOrderService)
        {
            _interrogationOrderService = interrogationOrderService ?? throw new ArgumentNullException(nameof(interrogationOrderService));
        }

        /// <summary>
        /// 处理问诊订单详情查询请求
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>订单详情</returns>
        public async Task<ApiResult<InterrogationOrderDetailDto>> Handle(InterrogationOrderDetailCommand request, CancellationToken cancellationToken)
        {
            return await _interrogationOrderService.GetInterrogationOrderDetailAsync(request);
        }
    }
}
